package com.xyh.transaction.excel;

import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.Row;

/**
 *  excel 固定行高的处理器 , 不影响表头的行高
 */
public class FixedRowHeightHandler implements RowWriteHandler {
    private final int columnWidth; // 列宽（字符数）

    public FixedRowHeightHandler(int columnWidth) {
        this.columnWidth = columnWidth;
    }

    @Override
    public void beforeRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Integer rowIndex,
                                Integer relativeRowIndex, Boolean isHead) {
        // 在创建行之前无需处理
    }

    @Override
    public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row,
                                Integer relativeRowIndex, Boolean isHead) {
        if (!isHead) {
            // 设置行高
            int rowHeight = (int) (columnWidth * 5.25); // 将列宽转换为行高（点）
            row.setHeightInPoints(rowHeight); // 设置行高
        }
    }
}
